package com.maycurobj.util;

import com.alibaba.fastjson.JSONObject;
import com.maycurobj.service.http.HttpAPIService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.*;

@Service
@Slf4j
public class DingMessageUtil {


    @Value("${ding-middle.ding-private}")
    private String DINGURL;

    /**
     * 基础消息推送
     */
    public void pushMessage(List<String> phones, String message) {
        try {
            String requestUrl=String.format("%s%s",DINGURL,"/dingBaseMessage/pushSimpleMessageByDing");
            Map<String, Object> req = new HashMap<>();
            req.put("msg", message);
            if (Objects.isNull(phones)) {
                req.put("phones", Arrays.asList("15267167276","15903019297","18058809660"));
            }else{
                req.put("phones",phones);
            }
            RestTemplate restTemplate = new RestTemplate();
            restTemplate.postForObject(requestUrl, req, org.json.JSONObject.class);
        } catch (Exception e) {
            log.info("钉钉推送消息异常");
        }
    }


}
